package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import com.leyou.item.entity.Category;
import com.leyou.pojo.dto.CategoryDTO;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    /**
     * 按id查询分类信息
     *
     * @param id 分类id
     * @return DTO对象
     */
    @Override
    public CategoryDTO findCategoryById(Long id) {
        return new CategoryDTO(this.getById(id));
    }

    //按id查询分类信息集
    @Override
    public List<CategoryDTO> findCategoryByIds(List<Long> ids) {
      return   CategoryDTO.convertEntityList(listByIds(ids));
    }

    //根据父类目id，查询子类目的集合
    @Override
    public List<CategoryDTO> findCategoryByParentId(Long pid) {
       return CategoryDTO.convertEntityList(query().eq("parent_id",pid).list());
    }

    //根据品牌id，查询商品分类的集合
    @Override
    public List<CategoryDTO> findCategoryByBrandId(Long id) {
        //先查询品牌id对应的
        return CategoryDTO.convertEntityList(baseMapper.findCategoryByBrandId(id));
    }
}
